import { View } from "../../../../mvc/core/View";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { MountTileItem } from "./MountTileItem";
import { MountStartsLogoSp } from "../mountStarts/MountStartsLogoSp";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ItemData } from "../../../resource/info/ItemData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ItemConfig } from "../../../resource/ItemConfig";
import { ModelUtil } from "../../../scene/player/info/ModelUtil";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { MountResInfo } from "../../../scene/player/info/MountResInfo";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { MountType } from "../../../scene/player/entity/MountType";
import { ActionType } from "../../../scene/modle/data/ActionType";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class MountSWFPanel
    
    export  class MountSWFPanel extends View
    {
        constructor()
        {
            super();
            this.initView();
            this.addEventListeners();
            this.mouseEnabled = false;
            return;
        }

        public get mountModel(): SWFPlayer
        {
            return this._mountModel;
        }

        public set mountModel(arg1: SWFPlayer)
        {
            this._mountModel = arg1;
            return;
        }

        /* internal  */initView(): void
        {
            this._btnLeft = ObjCreate.createGLoadedButton(ResFileConst.Left, -135, 15, 49, 26, this);
            this._btnLeft.drawNow();
            this._btnRight = ObjCreate.createGLoadedButton(ResFileConst.Right, 45, 15, 49, 26, this);
            this._btnRight.drawNow();
            this._txName = ObjCreate.createTextField("", -50, -114, 100, 20, this);
            this._txName.autoSize = flash.text.TextFieldAutoSize.CENTER;
            var loc1=ObjCreate.createTextField("LV.", length - 147, -90, 25, 20, this, GlobalStyle.textFormat6);
            this._txFeedLevel = ObjCreate.createTextField("", -127, -90, 40, 22, this, GlobalStyle.textFormat6);
            this._mountTileItem = new MountTileItem();
            this._mountTileItem.x = -127;
            this._mountTileItem.y = -115;
            this.addChild(this._mountTileItem);
            this._spSwf = new Object /* flash.display.Sprite */();
            var loc2;
            this._spSwf.mouseChildren = loc2 = false;
            this._spSwf.mouseEnabled = loc2;
            this.addChildAt(this._spSwf, 0);
            this._txChangingModel = ObjCreate.createTextField("", length - 47, 20, 50, 20, this, GlobalStyle.textFormat8);
            this._stReinBm = ObjCreate.createBitmap("", -90, -115, this);
            this._reinTipsTx = ObjCreate.createGTextField("", -87, -115, 34, 18, this);
            this._mountStartsLogo = new MountStartsLogoSp();
            this._mountStartsLogo.x = 68;
            this._mountStartsLogo.y = -116;
            this.addChild(this._mountStartsLogo);
            LoaderHelp.addResCallBack(ResFileConst.mount, this.onLoadBmResource);
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._loaded = true;
            if (this._mountIData) 
            {
                this.setReinBm(this._mountIData);
            }
            return;
        }

        /* internal  */setReinBm(arg1: ItemData): void
        {
            if (!arg1 || !arg1.itemExInfo) 
            {
                return;
            }
            if (arg1.itemExInfo.mount_rein != 0) 
            {
                this._stReinBm.bitmapData = GlobalClass.getBitmapData("mountReinLevel_" + this._mountIData.itemExInfo.mount_rein);
            }
            else 
            {
                this._stReinBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountRein_1);
            }
            return;
        }

        /* internal  */addEventListeners(): void
        {
            this._btnLeft.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnLeftClick);
            this._btnRight.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnRightClick);
            return;
        }

        protected onBtnLeftClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._mountModel) 
            {
                if (this._mountModel.currentDirection > 1) 
                {
                    --this._mountModel.currentDirection;
                }
                else 
                {
                    this._mountModel.currentDirection = 8;
                }
                this._mountModel.updateFrame(this._mountModel.currentAction, this._mountModel.currentDirection);
            }
            return;
        }

        protected onBtnRightClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._mountModel) 
            {
                if (this._mountModel.currentDirection < 8) 
                {
                    this._mountModel.currentDirection = this._mountModel.currentDirection + 1;
                }
                else 
                {
                    this._mountModel.currentDirection = 1;
                }
                this._mountModel.updateFrame(this._mountModel.currentAction, this._mountModel.currentDirection);
            }
            return;
        }

        public updateModelByCode(arg1: ItemData, arg2: int=0): void
        {
            this._mountIData = arg1;
            if (!this._mountIData || this._mountIData == ItemData.nullItemData) 
            {
                return;
            }
            if (!this._mountModel) 
            {
                this._mountModel = new SWFPlayer();
            }
            this._mountModel.loadComplete = this.onModuleLoadCompleteHandler;
            var loc1=ItemConfig.instance.getInfoByCode(arg1.itemCode);
            this._mountModel.load(ModelUtil.getModelSWF(arg1.itemExInfo.model_id), ModelType.Mount, new MountResInfo(arg1.itemExInfo.model_id));
            if (this._spSwf.contains(this._mountModel) == false) 
            {
                this._spSwf.addChildAt(this._mountModel, 0);
            }
            var loc2=arg1.itemExInfo.m_adv_lv + "☆";
            var loc3=arg1.itemInfo.item.name + " （" + arg1.itemExInfo.m_adv_lv + "☆）";
            var loc4=ColorConfig.instance.getItem("item", arg1.itemInfo.item.color.toString());
            this._txName.htmlText = HTMLUtil.addColor(loc3, loc4.color);
            this._txFeedLevel.text = arg1.itemExInfo.mount_level.toString();
            this._mountTileItem.setData(arg1);
            if (this._loaded) 
            {
                this.setReinBm(this._mountIData);
            }
            if (arg1.itemExInfo.mount_rein != 0) 
            {
                this._stReinBm.filters = null;
                this._reinTipsTx.toolTipData = HTMLUtil.addColor(Language.getString(70200), "#ffffff");
            }
            else 
            {
                this._stReinBm.filters = [FilterConst.colorFilter];
                this._reinTipsTx.toolTipData = HTMLUtil.addColor(Language.getString(70199), "#ffffff");
            }
            if (loc1.modelId === arg1.itemExInfo.model_id) 
            {
                this._txChangingModel.text = "";
            }
            else 
            {
                this._txChangingModel.text = Language.getString(70139);
            }
            this._mountStartsLogo.setMountData(this._mountIData);
            return;
        }

        /* internal  */onModuleLoadCompleteHandler(arg1: SWFPlayer): void
        {
            var loc2=0;
            var loc1=this._mountModel.url;
            this._mountModel.loadComplete = null;
            if (this._mountModel.movieClipData.modleType != MountType.Fly) 
            {
                if (this._mountModel.movieClipData.modleType != MountType.Rest) 
                {
                    loc2 = ActionType.MountStand;
                    this._mountModel.updateFrame(loc2, 2, true);
                    this._mountModel.updateCurrentFrame(0);
                    if (this._mountModel.url == "37015100.swf" || this._mountModel.url == "37016100.swf" || this._mountModel.url == "47015100.swf" || this._mountModel.url == "47016100.swf") 
                    {
                        this._spSwf.x = 0;
                        this._spSwf.y = 50;
                    }
                    else 
                    {
                        this._spSwf.x = 0;
                        this._spSwf.y = 0;
                    }
                }
                else 
                {
                    loc2 = ActionType.RestMountStand;
                    this._mountModel.updateFrame(loc2, 2, true);
                    this._mountModel.updateCurrentFrame(0);
                    this._spSwf.x = -30;
                    this._spSwf.y = 40;
                }
            }
            else 
            {
                loc2 = ActionType.flyMountStand;
                this._mountModel.updateFrame(loc2, 2, true);
                this._mountModel.updateCurrentFrame(0);
                if (this._mountModel.url == "37037400.swf" || this._mountModel.url == "37037500.swf") 
                {
                    this._spSwf.x = 20;
                    this._spSwf.y = 50;
                }
                else if (this._mountModel.url != "37038500.swf") 
                {
                    this._spSwf.x = 20;
                    this._spSwf.y = 30;
                }
                else 
                {
                    this._spSwf.x = 0;
                    this._spSwf.y = -30;
                }
            }
            this._mountModel.play();
            return;
        }

        public get isShowTurnBtn(): Boolean
        {
            return this._isShowTurnBtn;
        }

        public set isShowTurnBtn(arg1: Boolean)
        {
            this._isShowTurnBtn = arg1;
            if (this._isShowTurnBtn) 
            {
                if (!this.contains(this._btnLeft)) 
                {
                    this.addChild(this._btnLeft);
                }
                if (!this.contains(this._btnRight)) 
                {
                    this.addChild(this._btnRight);
                }
            }
            else 
            {
                if (this.contains(this._btnLeft)) 
                {
                    this.removeChild(this._btnLeft);
                }
                if (this.contains(this._btnRight)) 
                {
                    this.removeChild(this._btnRight);
                }
            }
            return;
        }

        public clean(): void
        {
            if (this._mountModel) 
            {
                this._mountModel.dispose();
                this._txName.text = "";
                this._txFeedLevel.text = "";
                this._mountStartsLogo.clean();
                this._txChangingModel.text = "";
                this._stReinBm.bitmapData = null;
            }
            return;
        }

        /* internal */ /* var */_isShowTurnBtn: Boolean;

        /* internal */ /* var */_btnLeft: GLoadedButton;

        /* internal */ /* var */_btnRight: GLoadedButton;

        /* internal */ /* var */_mountModel: SWFPlayer;

        /* internal */ /* var */_txGrade: GTextFiled;

        /* internal */ /* var */_txName: Object /* flash.text.TextField */;

        /* internal */ /* var */_txFeedLevel: Object /* flash.text.TextField */;

        /* internal */ /* var */_spSwf: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txChangingModel: Object /* flash.text.TextField */;

        /* internal */ /* var */_mountTileItem: MountTileItem;

        /* internal */ /* var */_stReinBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_reinTipsTx: GTextFiled;

        /* internal */ /* var */_mountIData: ItemData;

        /* internal */ /* var */_loaded: Boolean;

        /* internal */ /* var */_mountStartsLogo: MountStartsLogoSp;
    }
